#include "Base.h"
#include "GBProtocol.h"


BOOL GameMsg::Read(CSocketStream& iStream)
{
	if(m_pszBuffer != NULL)
	{
        iStream.Read((char*)m_pszBuffer, m_nLength);
	}
	return TRUE;
}

BOOL GameMsg::Write(CSocketStream& oStream) const
{
	if(m_pszBuffer != NULL)
	{
        oStream.Write((char*)m_pszBuffer, m_nLength); 
	}
	return TRUE;
}

BOOL GameHistoryMsg::Read(CSocketStream& iStream)
{
    iStream.Read((char*)&m_dwProductId, sizeof(m_dwProductId));
	iStream.Read((char*)&m_dwMatchId, sizeof(m_dwMatchId));
	iStream.Read((char*)&m_dwStageId, sizeof(m_dwStageId));
	iStream.Read((char*)&m_dwTableId, sizeof(m_dwTableId));
	iStream.Read((char*)&m_dwUserId, sizeof(m_dwUserId));
	iStream.Read((char*)&m_dwLookonType, sizeof(m_dwLookonType));

    iStream.Read((char*)&m_GameMsg.m_dwMsgId, sizeof(m_GameMsg.m_dwMsgId));
    iStream.Read((char*)&m_GameMsg.m_nLength, sizeof(m_GameMsg.m_nLength));

    if(m_GameMsg.m_pszBuffer != NULL)
	{
		m_GameMsg.Read(iStream);
		return TRUE;
	}
    return TRUE;
}

BOOL GameHistoryMsg::Write(CSocketStream& oStream) const
{
	oStream.Write((char*)&m_dwProductId, sizeof(m_dwProductId));
	oStream.Write((char*)&m_dwMatchId, sizeof(m_dwMatchId));
	oStream.Write((char*)&m_dwStageId, sizeof(m_dwStageId));
	oStream.Write((char*)&m_dwTableId, sizeof(m_dwTableId));
	oStream.Write((char*)&m_dwUserId, sizeof(m_dwUserId));
	oStream.Write((char*)&m_dwLookonType, sizeof(m_dwLookonType));

	oStream.Write((char*)&m_GameMsg.m_dwMsgId, sizeof(m_GameMsg.m_dwMsgId));
	oStream.Write((char*)&m_GameMsg.m_nLength, sizeof(m_GameMsg.m_nLength));
	m_GameMsg.Write(oStream);
	return TRUE;
}

BOOL GameHistoryMsg::FillHistoryMsg(Msg *pMsg)
{
	m_GameMsg.m_dwMsgId = pMsg->GetMsgId();
    m_GameMsg.m_nLength = pMsg->GetLength();
	if(m_GameMsg.m_pszBuffer != NULL)
	{
	    CSocketStream stream(m_GameMsg.m_pszBuffer, m_GameMsg.m_nLength);
	    pMsg->Write(stream);
	}
	return TRUE;
}
